<?php defined('BASEPATH') or exit('No direct script access allowed'); ?>

<?php 
	$USER = getAccountUserObject(true);
	$listEscort = $this->db->where("user_id = ".$USER->getId()." AND (apply_services = 1 OR published = 1) ")
					->get(TBL_ESCORT)->result();
	$nextPayment = $this->payment_log_entity->getNextPaymentDate($USER->getId());	
	 	
?>

<?php if($USER->getEscortsApplyNumber()):?>	
	<div class="dashboard-info-wrapper">
		<?php echo str_replace('%1', $USER->getEscortsApplyNumber(), language_translate('agent_dashboard_info_list_number_escort'));?>
		<div class="clear"></div>
		<?php if($nextPayment>0):?>
			<?php echo str_replace('%1', sysDateFormat($nextPayment,DATE_FORMAT), language_translate('agent_dashboard_info_next_payment'));?>
			<div class="clear"></div>
			<?php if($nextPayment <= time()):?>
				<span class="warning-text">
					<?php echo str_replace('%1', site_url_lang('agent/account/services'), language_translate('agent_dashboard_info_next_payment_contract'));?>
				</span>
			<?php endif;?>
		<?php endif;?>
	</div>
	<hr class="background-separate"/>
<?php endif;?>

<?php foreach($listEscort as $item):?>
	<?php 
		$ESCORT = $this->escort_entity->init('id',$item->id);
		$numberVisitted = $this->escort_visitted_entity->countNumberVisittedOfEscortInMonth($ESCORT->getId(),time());
		$numberVisitted = $numberVisitted ? $numberVisitted:0;
		$numberMessage = $this->visitor_contact_entity->countAllMessagesEscortReceipt($ESCORT->getId());
	?>
	<div class="dashboard-info-wrapper" id="item_escort_<?php echo $ESCORT->getId();?>">
		<div class="escort-item">
			<?php echo thumb($this->media_entity->getUserAvatarPicture($item->id), 100, 100);?>
			<div class="escort-name-x"><?php echo $ESCORT->getEscortName();?></div>
			<div class="escort-manage">
				<a href="<?php echo site_url_lang("agent/preview/?escort_id=".$ESCORT->getId());?>">
					<?php echo language_translate('load_escorts_view');?>
				</a>
				&nbsp;&nbsp;&nbsp;&nbsp;
				<a href="<?php echo site_url_lang("agent/profile/?escort_id=".$ESCORT->getId());//."&per_page=".$page ?>">
					<?php echo language_translate('load_escorts_edit');?>
				</a>
			</div>
		</div>
		
		<div class="escort-item-info">
			<?php echo str_replace('%1', $numberVisitted, language_translate('agent_dashboard_info_visits'))?>, 
			<?php echo str_replace('%1', $ESCORT->getNumberFirstStanding(), language_translate('agent_dashboard_info_listed_times'))?> <br/>
			
			<?php echo str_replace('%1', $ESCORT->getTimesPhoneDisplayed(), language_translate('agent_dashboard_info_see_phone'))?> <br/>
			<?php echo str_replace('%1', $numberMessage, language_translate('agent_dashboard_info_received_message'))?>
		</div>
		
		<div class="escort-item-publish">
			<div class="item-publish ui-corner-all" rel="<?php echo $ESCORT->getId();?>">
				<?php 
					if($ESCORT->getApplyServices() == 1){
						echo language_translate('agent_dashboard_info_unpublish');
					}else{
						echo language_translate('agent_dashboard_info_publish');
					}
				?>
			</div>
			<div class="item-publish-info" rel="<?php echo $ESCORT->getId();?>">
				<?php 
					if($ESCORT->getPublished() != 1 AND $ESCORT->getApplyServices() == 1){
						echo language_translate('agent_dashboard_info_publish_info');
					}
				?>
			</div>
		</div>
		
		<div class="clear"></div>	
	</div>
	<hr class="background-separate"/>
<?php endforeach;?>

<script type="text/javascript">
	$(document).ready(function(){
		$('.item-publish').bind('click',function(){
			$id = $(this).attr('rel');
			$this = this;
			$('#greyDiv').show();
			$.post(BASE_URI+'agent/my_account/publish_escort',{id:$id},function(res){
				$('#greyDiv').hide();
				if(res.result == 'ok'){
					//$('#item_escort_'+$id).fadeOut();
					$($this).text(res.message);
					$('.item-publish-info[rel='+$id+']').text(res.info);
				}else{
					alert(res.message);
				}
			},'json');
		});
	});
</script>